package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Gratitude;
import com.ruoyi.system.service.IGratitudeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 感恩墙Controller
 * 
 * @author ruoyi
 * @date 2025-10-27
 */
@RestController
@RequestMapping("/system/gratitude")
public class GratitudeController extends BaseController
{
    @Autowired
    private IGratitudeService gratitudeService;

    /**
     * 查询感恩墙列表
     */
    @PreAuthorize("@ss.hasPermi('system:gratitude:list')")
    @GetMapping("/list")
    public TableDataInfo list(Gratitude gratitude)
    {
        startPage();
        List<Gratitude> list = gratitudeService.selectGratitudeList(gratitude);
        return getDataTable(list);
    }

    /**
     * 导出感恩墙列表
     */
    @PreAuthorize("@ss.hasPermi('system:gratitude:export')")
    @Log(title = "感恩墙", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Gratitude gratitude)
    {
        List<Gratitude> list = gratitudeService.selectGratitudeList(gratitude);
        ExcelUtil<Gratitude> util = new ExcelUtil<Gratitude>(Gratitude.class);
        util.exportExcel(response, list, "感恩墙数据");
    }

    /**
     * 获取感恩墙详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:gratitude:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(gratitudeService.selectGratitudeById(id));
    }

    /**
     * 新增感恩墙
     */
    @PreAuthorize("@ss.hasPermi('system:gratitude:add')")
    @Log(title = "感恩墙", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Gratitude gratitude)
    {
        return toAjax(gratitudeService.insertGratitude(gratitude));
    }

    /**
     * 修改感恩墙
     */
    @PreAuthorize("@ss.hasPermi('system:gratitude:edit')")
    @Log(title = "感恩墙", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Gratitude gratitude)
    {
        return toAjax(gratitudeService.updateGratitude(gratitude));
    }

    /**
     * 删除感恩墙
     */
    @PreAuthorize("@ss.hasPermi('system:gratitude:remove')")
    @Log(title = "感恩墙", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(gratitudeService.deleteGratitudeByIds(ids));
    }
}
